package main

import (
	"fmt"
	"strings"
)

//#link: https://leetcode-cn.com/problems/ones-and-zeroes/
func main() {
	fmt.Println(convertBinaryToDecimal("100"))
}

func findMaxForm(strs []string, m int, n int) int {
	//dp[i][j][k]表示前i个字符中 j个0和k个1的最大值
	//dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j-str.zero][k-str.one])
	dp := make([][][]int, len(strs)+1)
	for i := range dp {
		dp[i] = make([][]int, m+1)
		for j := range dp[i] {
			dp[i][j] = make([]int, n+1)
		}
	}

	for i, str := range strs {
		zero := strings.Count(str, "0")
		one := len(str) - zero
		//zero, one := convertBinaryToDecimal(str)
		for j := 0; j <= m; j++ {
			for k := 0; k <= n; k++ {
				dp[i+1][j][k] = dp[i][j][k]
				if j >= zero && k >= one {
					dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j-zero][k-one]+1)
				}
			}
		}
	}

	return dp[len(strs)][m][n]

}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

/**
 * @Description: 二进制转10进制
 */
func convertBinaryToDecimal(str string) (zero, one int) {
	for i := len(str) - 1; i >= 0; i-- {
		if str[i] == '1' {
			one++
		} else {
			zero++
		}
	}
	return zero, one
}
